package com.fs.cv.service.impl;

import com.fs.cv.dao.DepartmentDao;
import com.fs.cv.pojo.pojodao.Student;
import com.fs.cv.pojo.pojodao.User;
import com.fs.cv.pojo.pojoview.StudentClassDepartment;
import com.fs.cv.pojo.pojoview.StudentInfo;
import com.fs.cv.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: hj
 * @createDate: 2020/9/30
 * @version: 1.0
 */
@Service
public class DepartmentServiceImlp implements DepartmentService {
@Autowired
private DepartmentDao departmentDao;
    @Override
    public PageInfo<StudentClassDepartment> getByPage(Integer currentPage, Integer pageSize) {
        //获取当前的登录对象
        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute("user");
        //获取登录对象的id，用于查询当前院系对应的学生
        int userId = user.getUserId();
       //拦截查询
        PageHelper.startPage(currentPage,pageSize);
        //查询
        List<StudentClassDepartment> studentClassDepartments = departmentDao.queryAll(userId);
        //页面计算
        PageInfo<StudentClassDepartment> PageInfo = new PageInfo<>(studentClassDepartments);
        return PageInfo;
    }

    @Override
    public List<StudentClassDepartment> queryByJava(String str) {
        return departmentDao.queryByJava(str);
    }

    @Override
    public StudentInfo getById(int studentId) {
        return departmentDao.queryById(studentId);
    }

    //根据班级姓名查询班级id
    @Override
    public int getClassIdByClassName(String ClassName) {
        return departmentDao.queryByClassName(ClassName);
    }

    @Override
    public int updateByClassId(int className, int studentId) {
        return departmentDao.updateByClassId(className,studentId);
    }

    @Override
    public Set<StudentClassDepartment> getByName(String studentName) {
        //获取当前的登录对象
        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute("user");
        //获取登录对象的id，用于查询当前院系对应的学生
        int userId = user.getUserId();
        String column="student_name";
        return departmentDao.queryByStudentName(column,studentName,userId);
    }
}

